package com.myproject.music.controller;

import com.myproject.music.BizException;
import com.myproject.music.domain.Concert;
import com.myproject.music.service.ConcertService;
import com.myproject.music.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/concert")
@Api(tags = "演唱会管理0515郭彦良")
public class ConcertController {
    @Autowired
    private ConcertService concertService;

    @ApiOperation("查询演唱会列表")
    @ApiImplicitParam(name="name", value="歌手名", dataType="string", dataTypeClass=String.class)
    @GetMapping("/list")
    public AjaxResult list(@RequestParam(value = "name", required = false) String creator) {
        List<Concert> list = concertService.selectConcertByParam(creator);
        return AjaxResult.success(list);
    }

    @ApiOperation(value="获取演唱会详细信息", notes = "根据演唱会ID获取详细信息")
    @ApiImplicitParam(name = "id", value="演唱会ID", required=true, dataType = "long", paramType="path", dataTypeClass=Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        Concert concert1=concertService.selectConcertById(id);
        if(concert1 ==null||concert1.getId()==null){
            throw new BizException(404,"演唱会"+id+"不存在");
        }
        return AjaxResult.success(concert1);
    }
    // @Log(title = "歌手管理",businessType = BusinessType.INSERT)

    @ApiOperation("新增演唱会")

    @PostMapping("/insertconcert")
    public AjaxResult add( @RequestBody Concert concert) {return AjaxResult.success(concertService.insertConcert(concert));}

    @ApiOperation("修改演唱会")
    @PutMapping
    public AjaxResult edit(@RequestBody Concert concert) {return AjaxResult.success(concertService.updateConcert(concert));}

    @ApiOperation("删除演唱会")
    @ApiImplicitParam(name="id", value = "演唱会ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return AjaxResult.success(concertService.deleteConcertById(id));
    }

    @ApiOperation("查询全部演唱会列表")
    @GetMapping("/concertlist")
    public AjaxResult getAllConcertList() {
        return AjaxResult.success(concertService.selectConcertAll());
    }
}
